package serverside;

/**
 *
 * @author AbdallaEssam
 */
public class Withdrawal extends Transaction {

    private CashDispenser cashDispenser;
    private Keypad keypad;
    private String tmp;
    public Withdrawal(int _cardID, DatabasePack.BankDatabase atmBankDatabase, Screen atmScreen,
            Keypad atmKeypad, CashDispenser atmCashDispenser) {
        super(_cardID, atmBankDatabase, atmScreen);
        keypad = atmKeypad;
        cashDispenser = atmCashDispenser;
    }

    @Override
    public void execute() {
        System.out.println("Transaction::Withdrawal");
        DatabasePack.BankDatabase bankDatabase = getBankDatabase();
        Screen screen = getScreen();
        
        screen.sendDataToClient("You can withdraw.");  
        //befor trying to withdraw we have to check cashDispenser to see 
        //if there are enough in this particular atm
        String result = bankDatabase.Withdraw(getCardID(), Integer.parseInt(
                tmp = keypad.getInput()));
        System.out.println("Transaction::Withdrawal client sent: " + 
                tmp);
        screen.sendDataToClient(result);
        System.out.println("Transaction::Withdrawal result: " + result +
                    "\n");
    }

}
